package com.utf999.qiangmanger.listener;

import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ProjectInitListener implements ServletContextListener{
	
	private static Log log = LogFactory.getLog(ProjectInitListener.class);
	
	public void contextInitialized(ServletContextEvent event) {
		ServletContext context = event.getServletContext();
		Properties prop = System.getProperties();
		InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("app.properties");
		try {
			prop.load(inputStream);
		} catch(Exception e) {
			ProjectInitListener.log.error(e.getMessage(), e);
		}
		
		context.setAttribute("prefix", prop.getProperty("server.prefix"));
	}

	public void contextDestroyed(ServletContextEvent event) {
		
	}
}